package com.juzipi.demo.servlet;

import org.springframework.core.annotation.Order;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

//多个Filter，序号越小，执行越早
@Order(1)
//URL 过滤配置
@WebFilter(filterName = "FilterDemo",urlPatterns = "/*")
public class FilterDemo implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        //init逻辑，该init将在服务器启动时被调用
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        //请求request处理逻辑
        //请求request封装逻辑
        //chain重新写回request和response

        System.out.println("拦截器");
        filterChain.doFilter(servletRequest,servletResponse);

    }

    @Override
    public void destroy() {
        //重写 destroy 逻辑，该逻辑将在服务器关闭时被调用
    }
}
